package com.stiff.manage.controller;

import com.stiff.manage.pojo.ItemDesc;
import com.stiff.manage.service.ItemDescService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("item/desc")
public class ItemDescController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ItemDescController.class);
    @Autowired
    private ItemDescService itemDescService;
    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<ItemDesc> queryItemDesc(@PathVariable(value = "itemId")Long itemId){
        try {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("【查询商品介绍】item_id={}",itemId);
            }
            ItemDesc itemDesc = this.itemDescService.queryById(itemId);
            if(null==itemDesc){
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(itemDesc);
        } catch (Exception e) {
            LOGGER.error("【查询失败】itemId="+itemId,e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
